#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<unordered_map>
#include<queue>
#include<stack>

using namespace std;

class Solution {
public:
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };
    int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {
        int n = maze.size(), m = maze[0].size();
        vector<vector<int>> vis(n, vector<int>(m, 0));
        queue<pair<int, int>> qt;
        qt.push({ entrance[0],entrance[1] });
        vis[entrance[0]][entrance[1]] = 1;
        int step = 0;
        while (qt.size())
        {
            int tmp = qt.size();
            step++;
            for (int i = 0; i < tmp; i++)
            {
                auto [a, b] = qt.front();
                qt.pop();
                for (int k = 0; k < 4; k++)
                {
                    int xi = a + dx[k];
                    int yi = b + dy[k];
                    if (xi >= 0 && xi < n && yi >= 0 && yi < m && maze[xi][yi] == '.' && vis[xi][yi] == 0)
                    {
                        if (xi == 0 || xi == n - 1 || yi == 0 || yi == m - 1) return step;
                        vis[xi][yi] = 1;
                        qt.push({ xi,yi });
                    }
                }
            }
        }
        return -1;
    }
};

int main() {
    return 0;
}